<template>
  <div id="app">
    <router-view v-if="isRouterAlive"></router-view>
  </div>
</template>
<script>
export default {
  name: "app",
  data() {
    return {
      isRouterAlive: true
    };
  },
  provide() {
    return {
      reload: this.reload
    };
  },
  created() {
    if(localStorage.getItem("icon") != undefined &&localStorage.getItem("icon") != "") {
      let icon = localStorage.getItem("icon");
      // 返回文档中所有a标签中rel为icon的href属性
      document.querySelector("[rel*='icon']").href = icon;
    }
  },
  methods: {
    te(arg) {
      const hasKey = this.$te(arg);
      if (hasKey) {
        const result = this.$t(arg);
        return result;
      }
      return arg;
    },
    reload() {
      this.isRouterAlive = false;
      this.$nextTick(function() {
        this.isRouterAlive = true;
      });
    }
  },
  watch: {
    $route(to) {
      if (to.meta.name) {
        document.title = this.te(to.meta.title) + "-" + this.te(to.meta.name);
      } else {
        document.title = this.te(to.meta.title);
      }
    }
  }
};
</script>

<style lang="less" scoped>

#app {
  height: 100vh;
  //background: @bgColor;
  width: 100%;
}
</style>